<?

include_once("sogeneric.php");
include_once("soset.php");
include_once("sodebug.php");
include_once("sodebug.inc");
include_once("dzkone.php");
include_once("dzgeneric.php");
include_once("dzconst.php");

include("sodebug.inc");

$soDebugLevel = SOD_DET;
$soDebugLogFile = "/tmp/luteet.log";

$kone = new dzKone();
$dbname = dzGetIniItem("general", DZID_DBACCESS, "app");
$kone->setDbAccess(dzGetIniItem($dbname, DZID_DBACCESS, "kone"));

$folder = "/turva/astrud/dzlink";

$dir = new soDir($folder, "file", "c");
$fcount = $dir->count();
for ($f = 0; $f < $fcount; $f++) {
    $name = $dir->getValue($f, "n");
    if (substr($name, strlen($name) -4) == ".las") {
#echo "$name\n";
        $error = 0;
        $streams = new soInputStream("file://".$folder."/".$name);
        $streams = soExplode($streams->Data, "\n\n");
        foreach ($streams as $stream) {
            $data = soExplode($stream, "\n");
            $set = new soSet();
            $set->joinKeyValueArray($data);
            $url = $set->encode();

            if (!$kone->_requestStr($url, "&")) $error = 1;
        }; // foreach
#        if (!$error) exec("rm /turva/$name");
    };
};

?>
